home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Freeware / Adobe Air 1.5 / AdobeAIRInstaller.exe / Adobe AIR / Versions / 1.0 / Adobe AIR Application Installer.swf / scripts / util / PNGHeaderUtil.as
Text File  |  2008-10-29  |  2KB  |  66 lines

  1. package util
  2. {
  3.    import flash.filesystem.File;
  4.    import flash.filesystem.FileMode;
  5.    import flash.filesystem.FileStream;
  6.    
  7.    public class PNGHeaderUtil
  8.    {
  9.       
  10.       public static const PNG_SIGNATURE:Array = [137,80,78,71,13,10,26,10];
  11.        
  12.       
  13.       public function PNGHeaderUtil()
  14.       {
  15.          super();
  16.       }
  17.       
  18.       public static function validatePNGSignature(param1:String) : Boolean
  19.       {
  20.          var fs:FileStream = null;
  21.          var f:File = null;
  22.          var val:int = 0;
  23.          var i:int = 0;
  24.          var nativePath:String = param1;
  25.          var valid:Boolean = false;
  26.          try
  27.          {
  28.             f = new File(nativePath);
  29.             fs = new FileStream();
  30.             fs.open(f,FileMode.READ);
  31.             if(fs.bytesAvailable < PNG_SIGNATURE.length)
  32.             {
  33.                valid = false;
  34.             }
  35.             else
  36.             {
  37.                valid = true;
  38.                i = 0;
  39.                while(i < PNG_SIGNATURE.length)
  40.                {
  41.                   val = fs.readUnsignedByte();
  42.                   if(val != PNG_SIGNATURE[i])
  43.                   {
  44.                      valid = false;
  45.                      break;
  46.                   }
  47.                   i++;
  48.                }
  49.             }
  50.          }
  51.          catch(e:Error)
  52.          {
  53.             valid = false;
  54.          }
  55.          finally
  56.          {
  57.             if(fs)
  58.             {
  59.                fs.close();
  60.             }
  61.             return valid;
  62.          }
  63.       }
  64.    }
  65. }
  66.